<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-row>
              <a-col :span="24">
                <a-form-model-item label="物料编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">
                  <a-input v-model="model.code" placeholder="请输入物料编号"></a-input>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="物料分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="classificationId">
              <j-dict-select-tag
                type="list"
                v-model="model.classificationId"
                dictCode="erp_goods_classification,name,id"
                placeholder="请选择物料分类"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="物料种类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="categoryName">
              <j-select-goods-category
                ref="selectGoodsCategory"
                v-model="model.categoryName"
                @onGoodsCategorySelected="onGoodsCategorySelected"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="种类编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="categoryNo">
              <a-input v-model="model.categoryNo" disabled placeholder="请输入种类编号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="规格型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="noneSpec">
              <a-input v-model="model.noneSpec" @change="noneSpecChange" placeholder="xxxKG*数字格式填写"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12" v-if="productShow || otherShow">
            <a-form-model-item label="包装规格(g)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="packSpec">
              <a-input v-model="model.packSpec" :min="1" placeholder="请输入包装规格(g)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="计量单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="meUnit">
              <j-dict-select-tag type="list" v-model="model.meUnit" dictCode="ji_unit" placeholder="请选择计量单位" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="辅助计量单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auUnit">
              <j-dict-select-tag
                type="list"
                v-model="model.auUnit"
                dictCode="zl_unit"
                placeholder="请选择辅助计量单位"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="安全库量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stockQuantity">
              <a-input-number v-model="model.stockQuantity" :min="0" placeholder="请输入安全库量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="转换率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="coRate">
              <a-input v-model="model.coRate" placeholder="请输入转换率"></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="12">
            <a-form-model-item label="所属仓库" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="warehouseName">
              <erp-warehouse
                ref="erpWarehouse"
                v-model="model.warehouseName"
                @onWarehouseSelected="onWarehouseSelected"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="配方号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="formulaNo">
              <a-input v-model="model.formulaNo" disabled placeholder="请输入配方号"></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="4">
            <a-form-model-item label="是否领料" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isUse">
              <j-dict-select-tag type="list" v-model="model.isUse" dictCode="yes_no" placeholder="请选择是否领料" />
            </a-form-model-item>
          </a-col>

          <a-col :span="12">
            <a-form-model-item label="条形码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="barCode">
              <a-input v-model="model.barCode" placeholder="请输入条形码"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12" v-if="productShow">
            <a-form-model-item label="配方保密" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isUse">
              <j-dict-select-tag type="list" v-model="model.isUse" dictCode="yes_no" placeholder="请选择是否领料" />
            </a-form-model-item>
          </a-col>

          <a-col :span="12">
            <a-form-model-item label="客户物料编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customCode">
              <a-input v-model="model.customCode" placeholder="请输入客户物料编号"></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="12">
            <a-form-model-item
              label="客户物料类型"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="customGoodsType"
            >
              <a-input v-model="model.customGoodsType" placeholder="请输入客户物料类型"></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="12">
            <a-form-model-item
              label="供应商要求名称"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="supplierRequireName"
            >
              <a-input v-model="model.supplierRequireName" placeholder="请输入供应商要求名称"></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="12">
            <a-form-model-item label="保质期（天）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qualityDays">
              <a-input v-model="model.qualityDays" placeholder="保质期（天）"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="在途天数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="onRoadDays">
              <a-input v-model="model.onRoadDays" placeholder="在途天数"></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="12">
            <a-form-model-item label="库存数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inventoryQuantity">
              <a-input-number v-model="model.inventoryQuantity" placeholder="请输入库存数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>

          <!-- <a-col :span="12">
            <a-form-model-item label="物料种类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="categoryCode">
              <j-dict-select-tag type="list" v-model="model.categoryCode"
                                 dictCode="erp_goods_category,name,id" placeholder="请选择物料种类"/>
            </a-form-model-item>
          </a-col> -->

          <a-col :span="12">
            <a-form-model-item label="是否有版样" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isPattern">
              <j-dict-select-tag
                type="list"
                v-model="model.isPattern"
                dictCode="yes_no"
                placeholder="请选择是否有版样"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否关联包材" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isAssBc">
              <j-dict-select-tag
                type="list"
                v-model="model.isAssBc"
                dictCode="yes_no"
                placeholder="请选择是否关联包材"
                @change="onChangeShowRow"
              />
            </a-form-model-item>
          </a-col>

          <a-col :span="12">
            <a-form-model-item label="是否启用" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="useStatus">
              <j-dict-select-tag
                type="list"
                v-model="model.useStatus"
                dictCode="erp_status"
                placeholder="请选择是否启用"
              />
            </a-form-model-item>
          </a-col>

          <a-col :span="12" v-if="packageShow">
            <a-form-model-item label="是否公用" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isPublic">
              <j-dict-select-tag type="list" v-model="model.isPublic" dictCode="yes_no" placeholder="请选择是否公用" />
            </a-form-model-item>
          </a-col>
          <!--v-if="packageShow||productShow"-->
          <a-col :span="12">
            <a-form-model-item label="所属人员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="belongUser">
              <a-row :gutter="4">
                <a-col :span="18">
                  <a-input v-model="model.belongUser" placeholder="请选择所属人员"></a-input>
                </a-col>

                <a-col :span="6">
                  <a-button @click="handleSelectEmployee" type="primary" :loading="confirmLoading">选择员工</a-button>
                </a-col>
              </a-row>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="包材种类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="packageCategory">
              <j-dict-select-tag
                type="list"
                v-model="model.packageCategory"
                dictCode="bc_type"
                placeholder="请选择包材种类"
              />
            </a-form-model-item>
          </a-col>

          <a-col :span="12" v-if="productShow">
            <a-form-model-item label="包装方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="packageType">
              <a-input v-model="model.packageType" placeholder="请输入包装方式"></a-input>
            </a-form-model-item>
          </a-col>

          <!--包材种类选择编织袋才会显示-->
          <!-- <a-col :span="12" v-if="packageShow">
            <a-form-model-item label="类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="packageType">
              <j-dict-select-tag type="list" v-model="model.packageType" dictCode="bc_type" placeholder="请选择类型" />
            </a-form-model-item>
          </a-col> -->
          <a-col :span="12" v-if="packageShow">
            <a-form-model-item label="尺寸" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="size">
              <a-input v-model="model.size" placeholder="请输入尺寸"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12" v-if="packageShow">
            <a-form-model-item label="材质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialQuality">
              <a-input v-model="model.materialQuality" placeholder="请输入材质"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12" v-if="packageShow || productShow">
            <a-form-model-item label="以前的订单" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="historyOrder">
              <a-input v-model="model.historyOrder" disable></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="24" v-if="packageShow">
            <a-form-model-item
              label="包装要求"
              :labelCol="textareaLabelCol"
              :wrapperCol="textareaWrapperCol"
              prop="packRequire"
            >
              <a-textarea v-model="model.packRequire" rows="4" placeholder="请输入备注" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <!--          <a-col :span="12">-->
        <!--            <a-form-model-item label="供应商" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplierId">-->
        <!--              <j-dict-select-tag type="list" v-model="model.supplierId"-->
        <!--                                 dictCode="erp_supplier,name,id" placeholder="请选择供应商"/>-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="textareaLabelCol" :wrapperCol="textareaWrapperCol" prop="remark">
              <a-textarea v-model="model.remark" rows="4" placeholder="请输入备注" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
    <employee-list-modal ref="selectEmployee" @handlerOk="handleSelectEmployeeOk" />
  </a-spin>
</template>

<script>
import { httpAction,putAction,postAction,getAction } from '@/api/manage'
import Big from 'big.js'

import ErpGoodsListModel from '@comp/base/modal/ErpGoodsListModal'
import EditableCell from '@comp/table/EditableCell'
import EmployeeListModal from '@/components/tsl/modules/EmployeeListModal.vue'


export default {
  name: 'ErpSparePartForm',
  components: {
    ErpGoodsListModel,
    EditableCell,
    EmployeeListModal,
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      productShow: false,
      otherShow: false,
      packageShow: false,
      switchValue: false,
      visible: false,
      modalWidth: 1250,
      category: '2',
      tabkeys: ['material', 'uphistorys'],
      model: {
        id: '',
        code: '',
        categoryName: '',
        categoryNo: '',
        useStatus: 1,
        isUse: 1,
        isPublic: 1,
        isAssBc: 1,
        isPattern: 1,
        noneSpec: '',
        packSpec: 0,
        meUnit: '',
        auUnit: '',
        customCode: '',
        coRate: 0,
        barCode: '',
        formulaNo: '',
        belongUser: '',
        packageType: '',
        onRoadDays: '',
        size: '',
        materialQuality: '',
        packRequire: '',
        packageCategory: '',
        warehouseCode: '',
        warehouseName: '',
        erpGoodsPackageList: [],
      },
      materielColumns: [
        {
          title: '包材编号',
          dataIndex: 'packageCode',
        },
        {
          title: '包材名称',
          dataIndex: 'packageName',
        },
        {
          title: '规格型号',
          dataIndex: 'noneSpec',
        },

        {
          title: '版样',
          dataIndex: 'pattern',
        },
        {
          title: '包材类别',
          dataIndex: 'packageType',
        },
        {
          title: '材质',
          dataIndex: 'materialQuality',
        },
        {
          title: '数量比例',
          dataIndex: 'num',
          scopedSlots: { customRender: 'num' },
          width: 150,
        },
        {
          title: '操作',
          dataIndex: 'operation',
          scopedSlots: { customRender: 'operation' },
        },
      ],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
        style: 'width: 28%;',
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      textareaLabelCol: {
        xs: { span: 12 },
        sm: { span: 2 },
      },
      textareaWrapperCol: {
        xs: { span: 40 },
        sm: { span: 21 },
      },
      confirmLoading: false,
      validatorRules: {
        code: [{ required: true, message: '请输入编号!' }],
        name: [{ required: true, message: '请输入名称!' }],
        noneSpec: [{ required: true, message: '请输入规格!' }],
        packSpec: [{ required: false, message: '请输入包装规格(g)!' }],
        categoryName: [{ required: true, message: '请输入物料种类!' }],
        customCode: [{ required: false, message: '请输入客户物料编号!' }],
        meUnit: [{ required: true, message: '请输入计量单位!' }],
        auUnit: [{ required: true, message: '请输入辅助单位!' }],
        useStatus: [{ required: true, message: '请输入状态!' }],
        coRate: [{ required: true, message: '请输入换算率!' }],
        classificationId: [{ required: true, message: '请输入物料分类!' }],
        isPattern: [{ required: false, message: '请输入是否有版样!' }],
        stockQuantity: [{ required: false, message: '请输入安全库量!' }],
        inventoryQuantity: [{ required: false, message: '请输入库存数量!' }],
        warehouseCode: [{ required: true, message: '请输入所属仓库!' }],
        isAssBc: [{ required: false, message: '请输入是否关联包材!' }],
        isPublic: [{ required: false, message: '请输入是否公用!' }],
        isUse: [{ required: false, message: '请输入是否领料!' }],
      },

      //配方列表column
      formulaTable: {
        loading: false,
        datasource: [],
        // 表头
        ipagination: {
          current: 1,
          pageSize: 30,
          pageSizeOptions: ['10', '30', '100'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
        formulaColumn: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            },
          },
          {
            title: '配方年',
            dataIndex: 'year',
          },
          {
            title: '配方编码',
            dataIndex: 'code',
          },
          {
            title: '配方号',
            dataIndex: 'no',
          },

          {
            title: '配方名称',
            dataIndex: 'pattern',
          },
          {
            title: '类别',
            dataIndex: 'category_dictText',
          },
          {
            title: '配方类型',
            dataIndex: 'materialQuality',
          },
          {
            title: '制单人',
            dataIndex: 'createByName',
            width: 150,
          },
          {
            title: '制单日期',
            dataIndex: 'createTime',
          },
          {
            title: '类别',
            dataIndex: 'type_dictText',
          },
        ],
      },
      url: {
        add: '/base/erpGoods/add',
        edit: '/base/erpGoods/edit',
        queryById: '/base/erpGoods/queryById',
      },
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    //选择员工方法
    handleSelectEmployeeOk(data) {
      console.log('选择员工：', data)
      if (data) {
        // console.log(data);
        // console.log(data.employeeName);
        this.model.belongUser = data.employeeName
        this.$forceUpdate() //重新渲染UI
        // console.log(data.employeeName,this.model.owner);
      }
    },
    //绑定所属员工
    handleSelectEmployee() {
      this.$refs.selectEmployee.visible = true
    },
    getSequenceNum() {
      let url = '/sys/fillRule/executeRuleByCode/wlbh'
      putAction(url, { name: '物料编号' }).then((res) => {
        // 执行成功，获取返回的值，并赋到页面上
        if (res.success) {
          this.model.code = res.result
        }
      })
    },
    //计算转换率
    safeDivision(numerator, denominator) {
      if (denominator === 0) {
        // 处理除数为0的情况，可以返回错误信息或默认值
        return 'Error: Division by zero'
      }
      console.log('计算')
      // 执行除法并保留两位小数
      return (numerator / denominator).toFixed(6)
    },

    noneSpecChange() {
      try {
        this.model.noneSpec = this.model.noneSpec.toUpperCase().trim()
        let tempSpec = this.model.noneSpec
        let k = tempSpec.indexOf('KG')
        let k1 = tempSpec.indexOf('G')
        if (k > 0) {
          let c = tempSpec.indexOf('*')
          let t1 = tempSpec.substr(0, k)
          let t2 = tempSpec.substr(c + 1)

          let bt1 = Number.parseInt(t1)
          let bt2 = Number.parseInt(t2)

          this.model.packSpec = bt1 * bt2 * 1000

          this.model.coRate = ((bt1 * bt2) / 1000).toFixed(6)
        } else if (k1 > 0) {
          let c = tempSpec.indexOf('*')
          let t1 = tempSpec.substr(0, k1)
          let t2 = tempSpec.substr(c + 1)
          let bt1 = new Big(t1)
          let bt2 = new Big(t2)
          let h = bt1.times(bt2)
          this.model.coRate = h.div(new Big(1000000))
        }
      } catch (e) {}
    },
    onWarehouseSelected(rows) {
      this.model.warehouseCode = rows.code
      this.model.warehouseName = rows.name
    },
    onGoodsCategorySelected(rows) {
      console.log(11111)

      this.model.categoryName = rows.name
      this.model.categoryNo = rows.code
      // 判断是否是成品，并且关联包材，如果是下方显示包材关联表
      let str = rows.name
      let productChar = '成品'
      let packageChar = '包材'
      let otherChar = '原料'
      let containsProductChar = str.includes(productChar)
      let containsPackageChar = str.includes(packageChar)
      let containsOtherChar = str.includes(otherChar)
      console.log('***********************')

      if (containsProductChar) {
        console.log('containsProductChar')
        this.productShow = true
        this.otherShow = false
        this.packageShow = false
      } else if (containsPackageChar) {
        console.log('containsPackageChar')
        this.productShow = false
        this.otherShow = false
        this.packageShow = true
      } else {
        console.log('containsOtherChar')

        this.productShow = false
        this.otherShow = true
        this.packageShow = false
      }
    },
    onChangeShowRow() {
      getAction('/goods/erpGoodsCategory/queryByCode', { code: this.model.categoryNo }).then((res) => {
        let str = res.result.name
        let char = '成品'
        let containsChar = str.includes(char)
        console.log(containsChar)
        console.log(this.model.isAssBc)
        if (containsChar && (this.model.isAssBc === 1 || this.model.isAssBc === '1')) {
          this.productShow = true
          console.log('1')
          console.log(this.productShow)
        } else {
          this.productShow = false
          console.log('2')
          console.log(this.productShow)
        }
      })
    },
    handleSwitchChange(newValue) {
      // newValue 是开关的新值
      console.log('开关的新值:', newValue)
      // 在这里调用你的方法或者进行其他操作
      if (newValue) {
        this.getSequenceNum()
      }
    },
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {

      console.log("展示model")
      this.model = Object.assign({}, record)
      console.log(this.model)
      //获取配方列表
      getAction('/base/erpGoodsFormula/queryByGoodsId',{ goodsId: this.model.id }).then((res)=>{
        this.formulaTable.datasource = res.result
        console.log(res.result)
      })
      getAction('/base/erpGoods/queryErpGoodsPackageByMainId', { goodsId: this.model.id }).then((res) => {
        this.model.erpGoodsPackageList = res.result
      })
      this.onChangeShowRow()
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    },
    // addRowCustom () {
    //   this.orderMainModel.jeecgOrderCustomerList.push({});
    //   this.$forceUpdate();
    // },
    goodsOk(datas) {
      console.log('-----------------------')
      console.log(datas)
      let _this = this
      postAction('/base/erpGoods/list/ids', { ids: datas }).then((res) => {
        console.log(res.result)
        let erpGoodsList = res.result
        erpGoodsList.forEach(function (item, index) {
          console.log(item, index)
          let detail = {}
          detail.packageId = item.id
          detail.packageCode = item.code
          detail.packageName = item.name
          detail.noneSpec = item.noneSpec
          detail.packageType = item.packageType
          detail.materialQuality = item.materialQuality
          console.log(_this.model.erpGoodsPackageList)
          _this.filterPackageId(item.id)
          _this.model.erpGoodsPackageList.push(detail)
        })
      })
    },
    filterPackageId(packageId) {
      this.model.erpGoodsPackageList = this.model.erpGoodsPackageList.filter(function (item) {
        return item.packageId !== packageId
      })
    },
    addMaterielPackage: function () {
      // 新增物料
      // console.log(this.$refs.selectGoodsList)
      this.$nextTick(() => {
        this.$refs.selectGoodsList.add()
      })
      // this.$refs.selectGoodsList.add();
      // this.$refs.selectGoodsList.title = "新增";
      // this.$refs.selectGoodsList.disableSubmit = false;
    },
    onCellChange(record, dataIndex, value) {
      console.log(this.model.erpGoodsPackageList)
      console.log(record)
      const dataSource = [...this.model.erpGoodsPackageList]
      const target = dataSource.find((item) => item.packageCode === record.packageCode)
      // console.log(target,key,dataIndex,value)
      if (record) {
        target[dataIndex] = value
        this.model.erpGoodsPackageList = dataSource
      }
    },
    onDelete(key) {
      const dataSource = [...this.model.erpGoodsPackageList]
      this.model.erpGoodsPackageList = dataSource.filter((item) => item.packageId !== key)
      // deleteAction('base/erpGoodsFormulaDetail/delete',{id:key}).then(res=>{
      //   if(res.success){
      //
      //   }
      // })
    },
    copy(record) {
      console.log(record)
      this.model = Object.assign({}, record)
      this.model.id = undefined
      this.model.code = ''
    },
  },
}
</script>